package edu.uwm.univesitydb.mock;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import edu.uwm.universitydb.swing.DataTableModel;

public class MockProfessorService extends DataTableModel {

	public MockProfessorService() {
		super(_colNames, _colTypes);
	}
	
	public boolean updateProfessor(String ssn, String name, int age, String rank, String speciality ) {
		Professor prof = getProfessorByID(ssn);
		if(prof != null) {
			prof._name = name;
			prof._age = age;
			prof._rank = rank;
			prof._speciality = speciality;
			return true;
		} else {
			return false;
		}
	}
	
	public boolean addProfessor(String ssn, String name, int age, String rank, String speciality ) {
		return _professors.add(new Professor(ssn, name, age, rank, speciality));
	}
	
	public boolean deleteByID(String ssn) {
		Professor match = null;
		for(Professor prof: _professors) {
			if(prof._ssn.equals(ssn)) {
				match = prof;
				break;
			}
		}
		return (match == null) ? false : _professors.remove(match);
	}

	@Override
	public int getRowCount() {
		return _professors.size();
	}
	@Override
	public Object getValueAt(int row, int col) {
		switch (col) {
		case 0:
			return _professors.get(row)._ssn;
		case 1:
			return _professors.get(row)._name;
		case 2:
			return _professors.get(row)._age;
		case 3:
			return _professors.get(row)._rank;
		case 4:
			return _professors.get(row)._speciality;
		default:
			return "Error";
		}
	}
	
	public String getSSNByID(String id) {
		Professor prof = getProfessorByID(id);
		if (prof != null) {
			return prof._ssn;
		} else {
			return "";
		}
	}
	
	public String getNameByID(String id) {
		Professor prof = getProfessorByID(id);
		if (prof != null) {
			return prof._name;
		} else {
			return "";
		}
	}
	
	public int getAgeByID(String id) {
		Professor prof = getProfessorByID(id);
		if (prof != null) {
			return prof._age;
		} else {
			return 0;
		}
	}
	
	public String getRankByID(String id) {
		Professor prof = getProfessorByID(id);
		if (prof != null) {
			return prof._rank;
		} else {
			return "";
		}
	}
	
	public String getSpecialityByID(String id) {
		Professor prof = getProfessorByID(id);
		if (prof != null) {
			return prof._speciality;
		} else {
		}
		return "";
	}

	private Professor getProfessorByID(String id) {
		for (Professor prof : _professors) {
			if (prof._ssn.equals(id)) {
				return prof;
			}
		}
		return null;
	}

	public static class Professor {
		public String _ssn;
		public String _name;
		public int _age;
		public String _rank;
		public String _speciality;
		public Professor(String ssn, String name, int age, String rank, String speciality) {
			_ssn = ssn;
			_name = name;
			_age = age;
			_speciality = speciality;
			_rank = rank;
		}
	}
	private static List<Professor> _professors = new ArrayList<Professor>(Arrays.asList(new Professor[] {
			new Professor("625-74-8528", "Stewart  Harrison", 53, "Assistant Professor", "Operations Research"),
			new Professor("143-31-3344", "Carla  Little", 62, "Research Professor", "Databases & Information Systems"),
			new Professor("115-75-9720", "Stella  Houston", 31, "Associate Professor", "Supply Chain Manufacturing and Logistics"),
			new Professor("708-45-3694", "Jeff  Parsons", 57, "Assistant Professor", "Thermal Sciences"),
			new Professor("147-23-5526", "Dianne  Vasquez", 54, "Associate Professor", "Computer Security & Information Assurance Systems"),
			new Professor("193-29-4821", "Shari  Morgan", 62, "Professor", "Mechanical Systems"),
			new Professor("700-59-0601", "Alonzo  Shelton", 35, "Research Professor", "Programming Languages & Compilers"),
			new Professor("256-22-5539", "Joey  Wood", 32, "Research Professor", "Nanoengineering"),
			new Professor("347-76-4465", "Luz  Beck", 26, "Adjunct Professor", "Materials Engineering"),
			new Professor("674-67-0203", "Deanna  Conner", 51, "Associate Professor", "Mechanical Systems"),
			new Professor("836-18-2285", "Laurence  Hudson", 33, "Lecturer", "Electronics"),
			new Professor("173-10-7862", "Roman  Newton", 36, "Adjunct Professor", "Communications and Signal Processing"),
			new Professor("717-91-5188", "Alicia  Strickland", 38, "Lecturer", "Medical & Bio Informatics"),
			new Professor("365-30-2876", "Fredrick  Hoffman", 56, "Associate Professor", "Transportation and municipal engineering"),
			new Professor("687-20-0319", "Conrad  Harmon", 28, "Associate Professor", "Medical & Bio Informatics"),
			new Professor("366-64-4380", "Katie  Drake", 60, "Adjunct Professor", "Computer Systems"),
			new Professor("682-16-1209", "Dawn  Cox", 36, "Professor", "Economics and Finance"),
			new Professor("214-96-9725", "Kurt  Ingram", 28, "Associate Professor", "Materials Engineering"),
			new Professor("305-73-9450", "Theresa  Roberts", 55, "Research Professor", "Databases & Information Systems"),
			new Professor("165-33-8709", "Tony  Hicks", 60, "Professor", "Mechanical Systems"),
			new Professor("911-30-0733", "Lela  Bowman", 36, "Adjunct Professor", "Programming Languages & Compilers"),
			new Professor("873-75-9197", "Kenny  Freeman", 63, "Research Professor", "Geotechnical engineering "),
			new Professor("305-73-9450", "Theresa  Roberts", 55, "Research Professor", "Databases & Information Systems"),
			new Professor("995-33-8709", "Tony  Hicks", 60, "Professor", "Mechanical Systems"),
			new Professor("881-30-0733", "Lela  Bowman", 36, "Adjunct Professor", "Programming Languages & Compilers"),
			new Professor("773-75-9197", "Kenny  Freeman", 63, "Research Professor", "Geotechnical engineering "),
	
	}));
	
	private static final long serialVersionUID = 5934593708603793544L;

	private static final String[] _colNames = new String[] {"SSN","Name", "Age", "Rank", "Speciality"};
	private static final Class<?>[] _colTypes = new Class<?>[] {String.class, String.class, Integer.class, String.class, String.class};
	
}
